<?php

/*
 * 数据库层公共类
 * @author kane.xie mr.ziyong@qq.com
 * @time 2012-5-15
 */

class CommonModel extends Model {

//    public function __construct() {
//        parent::__construct();
//    }
    //通过SQL语句查询
    public function selectBS($sql) {
        if (!empty($sql)) {
            $con = $this->pdoConnect();
            $rows = $con->query($sql);
            $rows->setFetchMode(PDO::FETCH_ASSOC);
            $res = $rows->fetchAll();
            if ($res) {
                return $res[0];
            } else {
                return false;
            }
        }
    }

    //添加
    public function addBS($sql) {
        if (!empty($sql)) {
            $con = $this->pdoConnect();
            $nums = $con->exec($sql);
            if ($nums) {
                $res = $con->lastInsertId();
                return $res;
            } else {
                return false;
            }
        }
    }

    //修改
    public function updateBS($sql) {
        if (!empty($sql)) {
            $con = $this->pdoConnect();
            $nums = $con->query($sql);
            if ($nums) {
                $res = $con->lastInsertId();
                return $res;
            } else {
                return false;
            }
        }
    }

    //删除
    public function deleteBS($sql) {
        if (!empty($sql)) {
            $con = $this->pdoConnect();
            $nums = $con->query($sql);
            if ($nums) {
                $res = $con->lastInsertId();
                return $res;
            } else {
                return false;
            }
        }
    }

}

?>